<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <html xmlns="http://www.w3.org/1999/xhtml">
		<head>
			<!-- template designed by Marco Von Ballmoos -->
			<title>Docs For Class Services_JSON</title>
			<link rel="stylesheet" href="../media/stylesheet.css" />
			<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'/>
		</head>
		<body>
			<div class="page-body">			
<h2 class="class-name"><img src="../media/images/Class_logo.png"
														alt=" Class"
														title=" Class"
														style="vertical-align: middle"> Services_JSON</h2>

<a name="sec-description"></a>
<div class="info-box">
	<div class="info-box-title">Description</div>
	<div class="nav-bar">
					<span class="disabled">Description</span> |
															<a href="#sec-method-summary">Methods</a> (<a href="#sec-methods">details</a>)
						
					</div>
	<div class="info-box-body">
        		<!-- ========== Info from phpDoc block ========= -->
<p class="short-description">Converts to and from JSON format.</p>
<p class="description"><p>Converts to and from JSON format.
 Brief example of use:
 <div class="src-code"><ol><li><div class="src-line">&nbsp;<span class="src-comm">//&nbsp;create&nbsp;a&nbsp;new&nbsp;instance&nbsp;of&nbsp;Services_JSON</span></div></li>
<li><div class="src-line">&nbsp;<span class="src-var">$json&nbsp;</span>=&nbsp;<span class="src-key">new&nbsp;</span><a href="../Services_JSON/Services_JSON.html#methodServices_JSON">Services_JSON</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line">&nbsp;<span class="src-comm">//&nbsp;convert&nbsp;a&nbsp;complexe&nbsp;value&nbsp;to&nbsp;JSON&nbsp;notation,&nbsp;and&nbsp;send&nbsp;it&nbsp;to&nbsp;the&nbsp;browser</span></div></li>
<li><div class="src-line">&nbsp;<span class="src-var">$value&nbsp;</span>=&nbsp;<span class="src-key">array</span><span class="src-sym">(</span><span class="src-str">'foo'</span><span class="src-sym">,&nbsp;</span><span class="src-str">'bar'</span><span class="src-sym">,&nbsp;</span><span class="src-key">array</span><span class="src-sym">(</span><span class="src-num">1</span><span class="src-sym">,&nbsp;</span><span class="src-num">2</span><span class="src-sym">,&nbsp;</span><span class="src-str">'baz'</span><span class="src-sym">)</span><span class="src-sym">,&nbsp;</span><span class="src-key">array</span><span class="src-sym">(</span><span class="src-num">3</span><span class="src-sym">,&nbsp;</span><span class="src-key">array</span><span class="src-sym">(</span><span class="src-num">4</span><span class="src-sym">)))</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;<span class="src-var">$output&nbsp;</span>=&nbsp;<span class="src-var">$json</span><span class="src-sym">-&gt;</span><a href="../Services_JSON/Services_JSON.html#methodencode">encode</a><span class="src-sym">(</span><span class="src-var">$value</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line">&nbsp;print<span class="src-sym">(</span><span class="src-var">$output</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;<span class="src-comm">//&nbsp;prints:&nbsp;[&quot;foo&quot;,&quot;bar&quot;,[1,2,&quot;baz&quot;],[3,[4]]]</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line">&nbsp;<span class="src-comm">//&nbsp;accept&nbsp;incoming&nbsp;POST&nbsp;data,&nbsp;assumed&nbsp;to&nbsp;be&nbsp;in&nbsp;JSON&nbsp;notation</span></div></li>
<li><div class="src-line">&nbsp;<span class="src-var">$input&nbsp;</span>=&nbsp;<a href="http://www.php.net/file_get_contents">file_get_contents</a><span class="src-sym">(</span><span class="src-str">'php://input'</span><span class="src-sym">,&nbsp;</span><span class="src-num">1000000</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;<span class="src-var">$value&nbsp;</span>=&nbsp;<span class="src-var">$json</span><span class="src-sym">-&gt;</span><a href="../Services_JSON/Services_JSON.html#methoddecode">decode</a><span class="src-sym">(</span><span class="src-var">$input</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
</ol></div></p></p>
		<p class="notes">
			Located in <a class="field" href="_JSON.php.html">/JSON.php</a> (line <span class="field"><a href="../__filesource/fsource_Services_JSON__JSON.php.html#a114">114</a></span>)
		</p>
		
				
		<pre></pre>
	
			</div>
</div>




	<a name="sec-method-summary"></a>
	<div class="info-box">
		<div class="info-box-title">Method Summary</span></div>
		<div class="nav-bar">
			<a href="#sec-description">Description</a> |
												<span class="disabled">Methods</span> (<a href="#sec-methods">details</a>)
		</div>
		<div class="info-box-body">			
			<div class="method-summary">
																																																																																<div class="method-definition">
					<img src="../media/images/Constructor.png" alt=" "/>
											<span class="method-result">Services_JSON</span>
										<a href="#Services_JSON" title="details" class="method-name">Services_JSON</a>
											([<span class="var-type">int</span>&nbsp;<span class="var-name">$use</span> = <span class="var-default">0</span>])
									</div>
																<div class="method-definition">
					<img src="../media/images/Method.png" alt=" "/>
											<span class="method-result">mixed</span>
										<a href="#decode" title="details" class="method-name">decode</a>
											(<span class="var-type">string</span>&nbsp;<span class="var-name">$str</span>)
									</div>
																<div class="method-definition">
					<img src="../media/images/Method.png" alt=" "/>
											<span class="method-result">mixed</span>
										<a href="#encode" title="details" class="method-name">encode</a>
											(<span class="var-type">mixed</span>&nbsp;<span class="var-name">$var</span>)
									</div>
																<div class="method-definition">
					<img src="../media/images/Method.png" alt=" "/>
											<span class="method-result">void</span>
										<a href="#isError" title="details" class="method-name">isError</a>
											(<span class="var-type"></span>&nbsp;<span class="var-name">$data</span>, [<span class="var-type"></span>&nbsp;<span class="var-name">$code</span> = <span class="var-default">null</span>])
									</div>
																<div class="method-definition">
					<img src="../media/images/PrivateMethod.png" alt=" "/>
											<span class="method-result">string</span>
										<a href="#name_value" title="details" class="method-name">name_value</a>
											(<span class="var-type">string</span>&nbsp;<span class="var-name">$name</span>, <span class="var-type">mixed</span>&nbsp;<span class="var-name">$value</span>)
									</div>
																<div class="method-definition">
					<img src="../media/images/PrivateMethod.png" alt=" "/>
											<span class="method-result">string</span>
										<a href="#reduce_string" title="details" class="method-name">reduce_string</a>
											(<span class="var-type">$str</span>&nbsp;<span class="var-name">$str</span>)
									</div>
																<div class="method-definition">
					<img src="../media/images/PrivateMethod.png" alt=" "/>
											<span class="method-result">string</span>
										<a href="#utf82utf16" title="details" class="method-name">utf82utf16</a>
											(<span class="var-type">string</span>&nbsp;<span class="var-name">$utf8</span>)
									</div>
																<div class="method-definition">
					<img src="../media/images/PrivateMethod.png" alt=" "/>
											<span class="method-result">string</span>
										<a href="#utf162utf8" title="details" class="method-name">utf162utf8</a>
											(<span class="var-type">string</span>&nbsp;<span class="var-name">$utf16</span>)
									</div>
											</div>
		</div>
	</div>		

	
	<a name="sec-methods"></a>
	<div class="info-box">
		<div class="info-box-title">Methods</div>
		<div class="nav-bar">
			<a href="#sec-description">Description</a> |
													<a href="#sec-method-summary">Methods</a> (<span class="disabled">details</span>)
						
		</div>
		<div class="info-box-body">
			<A NAME='method_detail'></A>
<a name="methodServices_JSON" id="Services_JSON"><!-- --></a>
<div class="evenrow">
	
	<div class="method-header">
		<img src="../media/images/Constructor.png" />
		<span class="method-title">Constructor Services_JSON</span> (line <span class="line-number"><a href="../__filesource/fsource_Services_JSON__JSON.php.html#a132">132</a></span>)
	</div> 
	
	<!-- ========== Info from phpDoc block ========= -->
<p class="short-description">constructs a new JSON instance</p>
<p class="description"><p>constructs a new JSON instance</p></p>
	
	<div class="method-signature">
		<span class="method-result">Services_JSON</span>
		<span class="method-name">
			Services_JSON
		</span>
					([<span class="var-type">int</span>&nbsp;<span class="var-name">$use</span> = <span class="var-default">0</span>])
			</div>
	
			<ul class="parameters">
					<li>
				<span class="var-type">int</span>
				<span class="var-name">$use</span><span class="var-description">: object behavior flags; combine with boolean-OR
                           possible values:<ul><li>SERVICES_JSON_LOOSE_TYPE:  loose typing.
                                   &quot;{...}&quot; syntax creates associative arrays
                                   instead of objects in decode().</li><li>SERVICES_JSON_SUPPRESS_ERRORS:  error suppression.
                                   Values which can't be encoded (e.g. resources)
                                   appear as NULL instead of throwing errors.
                                   By default, a deeply-nested resource will
                                   bubble up with an error, so all return values
                                   from encode() should be checked with isError()</li></ul></span>			</li>
				</ul>
		
			
	</div>
<a name="methoddecode" id="decode"><!-- --></a>
<div class="oddrow">
	
	<div class="method-header">
		<img src="../media/images/Method.png" />
		<span class="method-title">decode</span> (line <span class="line-number"><a href="../__filesource/fsource_Services_JSON__JSON.php.html#a483">483</a></span>)
	</div> 
	
	<!-- ========== Info from phpDoc block ========= -->
<p class="short-description">decodes a JSON string into appropriate variable</p>
<p class="description"><p>decodes a JSON string into appropriate variable</p></p>
	<ul class="tags">
				<li><span class="field">return:</span> number, boolean, string, array, or object                   corresponding to given JSON input string.                   See argument 1 to Services_JSON() above for object-output behavior.                   Note that decode() always returns strings                   in ASCII or UTF-8 format!</li>
				<li><span class="field">access:</span> public</li>
			</ul>
	
	<div class="method-signature">
		<span class="method-result">mixed</span>
		<span class="method-name">
			decode
		</span>
					(<span class="var-type">string</span>&nbsp;<span class="var-name">$str</span>)
			</div>
	
			<ul class="parameters">
					<li>
				<span class="var-type">string</span>
				<span class="var-name">$str</span><span class="var-description">: JSON-formatted string</span>			</li>
				</ul>
		
			
	</div>
<a name="methodencode" id="encode"><!-- --></a>
<div class="evenrow">
	
	<div class="method-header">
		<img src="../media/images/Method.png" />
		<span class="method-title">encode</span> (line <span class="line-number"><a href="../__filesource/fsource_Services_JSON__JSON.php.html#a236">236</a></span>)
	</div> 
	
	<!-- ========== Info from phpDoc block ========= -->
<p class="short-description">encodes an arbitrary variable into JSON format</p>
<p class="description"><p>encodes an arbitrary variable into JSON format</p></p>
	<ul class="tags">
				<li><span class="field">return:</span> JSON string representation of input var or an error if a problem occurs</li>
				<li><span class="field">access:</span> public</li>
			</ul>
	
	<div class="method-signature">
		<span class="method-result">mixed</span>
		<span class="method-name">
			encode
		</span>
					(<span class="var-type">mixed</span>&nbsp;<span class="var-name">$var</span>)
			</div>
	
			<ul class="parameters">
					<li>
				<span class="var-type">mixed</span>
				<span class="var-name">$var</span><span class="var-description">: any number, boolean, string, array, or object to be encoded.                           see argument 1 to Services_JSON() above for array-parsing behavior.                           if var is a strng, note that encode() always expects it                           to be in ASCII or UTF-8 format!</span>			</li>
				</ul>
		
			
	</div>
<a name="methodisError" id="isError"><!-- --></a>
<div class="oddrow">
	
	<div class="method-header">
		<img src="../media/images/Method.png" />
		<span class="method-title">isError</span> (line <span class="line-number"><a href="../__filesource/fsource_Services_JSON__JSON.php.html#a765">765</a></span>)
	</div> 
	
	<!-- ========== Info from phpDoc block ========= -->
	<ul class="tags">
				<li><span class="field">todo:</span> Ultimately, this should just call PEAR::isError()</li>
			</ul>
	
	<div class="method-signature">
		<span class="method-result">void</span>
		<span class="method-name">
			isError
		</span>
					(<span class="var-type"></span>&nbsp;<span class="var-name">$data</span>, [<span class="var-type"></span>&nbsp;<span class="var-name">$code</span> = <span class="var-default">null</span>])
			</div>
	
			<ul class="parameters">
					<li>
				<span class="var-type"></span>
				<span class="var-name">$data</span>			</li>
					<li>
				<span class="var-type"></span>
				<span class="var-name">$code</span>			</li>
				</ul>
		
			
	</div>
<a name="methodname_value" id="name_value"><!-- --></a>
<div class="evenrow">
	
	<div class="method-header">
		<img src="../media/images/PrivateMethod.png" />
		<span class="method-title">name_value</span> (line <span class="line-number"><a href="../__filesource/fsource_Services_JSON__JSON.php.html#a433">433</a></span>)
	</div> 
	
	<!-- ========== Info from phpDoc block ========= -->
<p class="short-description">array-walking function for use in generating JSON-formatted name-value pairs</p>
<p class="description"><p>array-walking function for use in generating JSON-formatted name-value pairs</p></p>
	<ul class="tags">
				<li><span class="field">return:</span> JSON-formatted name-value pair, like '&quot;name&quot;:value'</li>
				<li><span class="field">access:</span> private</li>
			</ul>
	
	<div class="method-signature">
		<span class="method-result">string</span>
		<span class="method-name">
			name_value
		</span>
					(<span class="var-type">string</span>&nbsp;<span class="var-name">$name</span>, <span class="var-type">mixed</span>&nbsp;<span class="var-name">$value</span>)
			</div>
	
			<ul class="parameters">
					<li>
				<span class="var-type">string</span>
				<span class="var-name">$name</span><span class="var-description">: name of key to use</span>			</li>
					<li>
				<span class="var-type">mixed</span>
				<span class="var-name">$value</span><span class="var-description">: reference to an array element to be encoded</span>			</li>
				</ul>
		
			
	</div>
<a name="methodreduce_string" id="reduce_string"><!-- --></a>
<div class="oddrow">
	
	<div class="method-header">
		<img src="../media/images/PrivateMethod.png" />
		<span class="method-title">reduce_string</span> (line <span class="line-number"><a href="../__filesource/fsource_Services_JSON__JSON.php.html#a452">452</a></span>)
	</div> 
	
	<!-- ========== Info from phpDoc block ========= -->
<p class="short-description">reduce a string by removing leading and trailing comments and whitespace</p>
<p class="description"><p>reduce a string by removing leading and trailing comments and whitespace</p></p>
	<ul class="tags">
				<li><span class="field">return:</span> string value stripped of comments and whitespace</li>
				<li><span class="field">access:</span> private</li>
			</ul>
	
	<div class="method-signature">
		<span class="method-result">string</span>
		<span class="method-name">
			reduce_string
		</span>
					(<span class="var-type">$str</span>&nbsp;<span class="var-name">$str</span>)
			</div>
	
			<ul class="parameters">
					<li>
				<span class="var-type">$str</span>
				<span class="var-name">$str</span><span class="var-description">: string      string value to strip of comments and whitespace</span>			</li>
				</ul>
		
			
	</div>
<a name="methodutf82utf16" id="utf82utf16"><!-- --></a>
<div class="evenrow">
	
	<div class="method-header">
		<img src="../media/images/PrivateMethod.png" />
		<span class="method-title">utf82utf16</span> (line <span class="line-number"><a href="../__filesource/fsource_Services_JSON__JSON.php.html#a192">192</a></span>)
	</div> 
	
	<!-- ========== Info from phpDoc block ========= -->
<p class="short-description">convert a string from one UTF-8 char to one UTF-16 char
 Normally should be handled by mb_convert_encoding, but provides a slower PHP-only method for installations that lack the multibye string extension.</p>
<p class="description"><p>convert a string from one UTF-8 char to one UTF-16 char
 Normally should be handled by mb_convert_encoding, but provides a slower PHP-only method for installations that lack the multibye string extension.</p></p>
	<ul class="tags">
				<li><span class="field">return:</span> UTF-16 character</li>
				<li><span class="field">access:</span> private</li>
			</ul>
	
	<div class="method-signature">
		<span class="method-result">string</span>
		<span class="method-name">
			utf82utf16
		</span>
					(<span class="var-type">string</span>&nbsp;<span class="var-name">$utf8</span>)
			</div>
	
			<ul class="parameters">
					<li>
				<span class="var-type">string</span>
				<span class="var-name">$utf8</span><span class="var-description">: UTF-8 character</span>			</li>
				</ul>
		
			
	</div>
<a name="methodutf162utf8" id="utf162utf8"><!-- --></a>
<div class="oddrow">
	
	<div class="method-header">
		<img src="../media/images/PrivateMethod.png" />
		<span class="method-title">utf162utf8</span> (line <span class="line-number"><a href="../__filesource/fsource_Services_JSON__JSON.php.html#a148">148</a></span>)
	</div> 
	
	<!-- ========== Info from phpDoc block ========= -->
<p class="short-description">convert a string from one UTF-16 char to one UTF-8 char
 Normally should be handled by mb_convert_encoding, but provides a slower PHP-only method for installations that lack the multibye string extension.</p>
<p class="description"><p>convert a string from one UTF-16 char to one UTF-8 char
 Normally should be handled by mb_convert_encoding, but provides a slower PHP-only method for installations that lack the multibye string extension.</p></p>
	<ul class="tags">
				<li><span class="field">return:</span> UTF-8 character</li>
				<li><span class="field">access:</span> private</li>
			</ul>
	
	<div class="method-signature">
		<span class="method-result">string</span>
		<span class="method-name">
			utf162utf8
		</span>
					(<span class="var-type">string</span>&nbsp;<span class="var-name">$utf16</span>)
			</div>
	
			<ul class="parameters">
					<li>
				<span class="var-type">string</span>
				<span class="var-name">$utf16</span><span class="var-description">: UTF-16 character</span>			</li>
				</ul>
		
			
	</div>
						
		</div>
	</div>

	
	<p class="notes" id="credit">
		Documentation generated on Thu, 22 Oct 2009 12:54:41 -0700 by <a href="http://www.phpdoc.org" target="_blank">phpDocumentor 1.4.3</a>
	</p>
	</div></body>
</html>